package com.itheima.reggie.mapper;

import com.itheima.reggie.dto.SetmealDto;
import com.itheima.reggie.entity.Setmeal;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

public interface SetmealMapper {
    //根据id套餐信息
    @Select("select count(*) from setmeal where category_id=#{categoryId} and is_deleted=0")
    Integer findById(Long categoryId);

    //保存套餐信息
    @Insert("insert into setmeal values (null,#{categoryId},#{name},#{price},#{status},#{code},#{description},#{image}" +
            ",#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    Integer save(SetmealDto setmealDto);

    //分表查询套餐信息
    List<Setmeal> findSetmeal(@Param("name") String name);

    //查询指定id列表数据中含有启用套餐的个数
    Integer countById(@Param("ids") List<Long> ids);
    //删除指定的多个id的套餐(伪删除)
    Integer deleteByIds(@Param("updateUser") Long updateUser,
                        @Param("updateTime") LocalDateTime updateTime,
                        @Param("ids") List<Long> ids);
    //根据id查询一个套餐和多个菜品
    SetmealDto findById1(Long id);
    //根据id获取菜品列表数据
    @Select("select * from setmeal where category_id = {categoryId} and is_deleted=0 order by sort asc")
    List<Setmeal> findByCategoryId(Long categoryId);
}
